home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 4_12.lha / 4_12 / 4_12a.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  887b  |  53 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6. include <ctype.h>
  7.  
  8. / print out a printable version of
  9. / the character read in
  10. nt dochar()
  11.  
  12.    char c;
  13.    if (!cin.get(c))
  14. return 0;
  15.  
  16.    if (isascii(c) && isprint(c))
  17. {
  18. cout.put(c);
  19. cout.put('_');
  20. }
  21.  
  22.    else
  23. cout << form("%2.2x", c);
  24.    return 1;
  25.  
  26.  
  27. / print a group of five characters
  28. nt dogroup()
  29.  
  30.    for (int chr_count = 5; chr_count-- > 0; )
  31. if (!dochar())
  32.     return 0;
  33.    return 1;
  34.  
  35.  
  36. / Print out six groups of characters separated
  37. / by spaces. Precede each line with the count
  38. / of characters printed so far.
  39. nt main(int, char**)
  40.  
  41.    for (int chr_cnt = 0; cin; chr_cnt += 30)
  42. {
  43. cout << dec(chr_cnt, 5) << "  ";
  44.  
  45. for (int grp_count = 6;
  46.      grp_count-- > 0 && dogroup(); )
  47.     cout << "  ";
  48.  
  49. cout << "\n";
  50. }
  51.    return 0;
  52.  
  53.